﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using ZHDJ.Data.Models.Center;
using ZHDJ.Data.Models.Org;
using ZHDJ.PersonalCenter.BLL;
using ZHDJ.WebPage;

namespace ZHDJ.PersonalCenter.Module.RelationshipTransfer
{
    public partial class RelationshipTransferView : PageBase
    {
        public string RelationID
        {
            get
            {
                return this.Request["RelationID"] ?? "";
            }
        }


        public string mode
        {
            get
            {
                return this.Request["mode"] ?? "";
            }
        }
        public DataTable ProcessInfo
        {
            get
            {
                return PartyRelationshipTransfer.GetProcessesView(this.RelationID);
            }
        }

        public PartyRelationshipTransfer TransferModel
        {
            get;
            set;
        }

        public PartyOrgMember OrgMemberModel
        {
            get;
            set;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadData();
            this.ucHistory1.LoginID = CurrentUser.LoginID;
            this.ucHistory1.mode = this.mode;
            if (!string.IsNullOrEmpty(this.mode))
            {
                this.divConent.Attributes["style"] = "overflow-y:auto;";
            }

            //如果是申请人查看则不能打印
            if (OrgMemberModel.LoginID == CurrentUser.LoginID) {
                this.btnPrint.Visible = false;
            }
        }
        public string GetBranchName(object id)
        {
            var dd = ZHDJ.WebPage.ControlBusiness.GetBranchPickerText(id.ToString());
            if (dd == "")
                dd = id.ToString();
            return dd;
        }
        /// <summary>
        /// 加载申请人信息
        /// </summary>
        public void LoadData()
        {
            ZHDJ.Core.Log.Log4netHelper.WriteLog(this.RelationID.ToString());
            this.aWord.HRef = "TWord.aspx?RelationID=" + this.RelationID;
            TransferModel = DB.PartyRelationshipTransfers.Find(this.RelationID);
            OrgMemberModel = DB.PartyOrgMembers.Find(TransferModel.Applicant);

            if (TransferModel.Status == "同意转组织")
            {
                //已经结束
                this.tableHuizhi.Visible = true;
                DataTable dt = ProcessInfo.Copy();
                if (dt.Rows.Count > 0)
                {
                    this.ltDoneBy.Text = dt.Rows[dt.Rows.Count - 1]["UserName"].ToString();
                    this.ltDoneTime.Text = Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1]["CreateTime"].ToString()).ToString("yyyy年MM月dd日");
                    this.ltDoneByMobileNo.Text = dt.Rows[dt.Rows.Count - 1]["MobileNo"].ToString();
                }
            }
            else
            {
                this.tableHuizhi.Visible = false;
            }
        }

        public string GetMemberCost(int index)
        {
            if (string.IsNullOrEmpty(TransferModel.MemberCostTime))
            {
                return "";
            }
            string[] temp = TransferModel.MemberCostTime.Split('-');
            if (temp.Length != 2)
            {
                return "";
            }
            return temp[index];
        }

        public string GetPoliticsLineamentName(string value)
        {
            DropDownList list = new DropDownList();
            ControlBusiness.ControlBindDataDictionary(list, "ZHDJ.Member.PoliticsLineament");
            list.SelectedValue = value;
            return list.Items[list.SelectedIndex].Text.Replace("党员", "");
        }
    }
}